package GUI;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTabbedPane;
import javax.swing.JMenuBar;

import java.awt.FlowLayout;

import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.JLabel;

import java.awt.Color;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JSplitPane;
import javax.swing.BoxLayout;
import javax.swing.JTextField;

import java.awt.GridBagLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class MainWindow extends JFrame {

	private JPanel contentPane;
	private JMenuItem mntmOpenData;
	private JPanel main_status_panel;
	public static JLabel statusBarText;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindow frame = new MainWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public MainWindow() {
		setTitle("Vestbjerg Byggecenter A/S");
		setPreferredSize(new Dimension(1024, 768));
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 762, 611);
		
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		
		JMenu mnFile = new JMenu("File");
		mnFile.setMnemonic('f');
		menuBar.add(mnFile);
		
		mntmOpenData = new JMenuItem("\u00C5bn Data");
		mntmOpenData.setMnemonic('O');
		mnFile.add(mntmOpenData);
		
		JSeparator separator = new JSeparator();
		mnFile.add(separator);
		
		JMenuItem mntmAfslutProgrammet = new JMenuItem("Afslut Programmet");
		mntmAfslutProgrammet.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exitProgram();
			}
		});
		mntmAfslutProgrammet.setMnemonic('A');
		mnFile.add(mntmAfslutProgrammet);
		
		JMenu mnHjlp = new JMenu("Hj\u00E6lp");
		mnHjlp.setMnemonic('H');
		menuBar.add(mnHjlp);
		
		JMenuItem mntmOmProgrammet = new JMenuItem("Om Programmet");
		mntmOmProgrammet.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				about();
			}
		});
		mntmOmProgrammet.setMnemonic('O');
		mnHjlp.add(mntmOmProgrammet);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(5, 5));
		setContentPane(contentPane);
		
		main_status_panel = new JPanel();
		main_status_panel.setBorder(new SoftBevelBorder(BevelBorder.RAISED, null, null, null, null));
		FlowLayout fl_main_status_panel = (FlowLayout) main_status_panel.getLayout();
		fl_main_status_panel.setAlignment(FlowLayout.LEFT);
		fl_main_status_panel.setHgap(10);
		contentPane.add(main_status_panel, BorderLayout.SOUTH);
		
		statusBarText = new JLabel(" ");
		statusBarText.setForeground(Color.BLACK);
		main_status_panel.add(statusBarText);
		
		JPanel main_main_panel = new JPanel();
		contentPane.add(main_main_panel, BorderLayout.CENTER);
		main_main_panel.setLayout(new BorderLayout(0, 0));
		
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		main_main_panel.add(tabbedPane, BorderLayout.CENTER);
		
		// new sale panel
		JPanel newSalePanel = new NewSalePanel();
		//JTabbedPane tabbedPane_2 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.addTab("Nyt Salg", null, newSalePanel, null);
		
		// sales panel
		JPanel salesPanel = new SalesPanel();
		//JTabbedPane tabbedPane_1 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.addTab("Salgshistorik", null, salesPanel, null);
		
		// item panel
		JPanel itemPanel = new ItemPanel();
		//JTabbedPane tabbedPane_3 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.addTab("Varer", null, itemPanel, null);
		
		// person panel
		JPanel personPanel = new PersonPanel();
		//JTabbedPane tabbedPane_4 = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.addTab("Personer", null, personPanel, null);
		
		
		
	}
	
	public JLabel getStatusBarText() {
		return statusBarText;
	}
	
	public void setStatusBarText(String newStatusBarText){
		statusBarText.setText(newStatusBarText);
	}
	
	public void about() {
		JOptionPane.showMessageDialog(this, "Dette program blev udviklet ved University College Nordjylland af dmaa0214 Gruppe 3 - Kim, Mads, Mike og Mike. Juni 2014");
	}
	
	public void exitProgram() {
		System.exit(DISPOSE_ON_CLOSE);
	}
}
